import NftEggsNFT from "../contracts/NftEggsNFT.cdc"

// NFT交易，将NFT从拥有者账户转到另一个账户
transaction(recipient: Address, withdrawID: UInt64) {

    prepare(acct: AuthAccount) {

        // 获取收件人公共帐户对象
        let recipient = getAccount(recipient)

        // 对签名人（拥有者）NFT集合的引用
        let collectionRef = acct.borrow<&NftEggsNFT.Collection>(from: /storage/NFTCollection)
            ?? panic("Could not borrow a reference to the owner's collection")

        // 对收件人的NFT集合的引用
        let depositRef = recipient.getCapability(/public/NFTCollection)
            .borrow<&{NftEggsNFT.NftEggsNFTCollectionPublic}>()
            ?? panic("Could not borrow a reference to the receiver's collection")

        // 从拥有者账户提取NFT
        let nft <- collectionRef.withdraw(withdrawID: withdrawID)

        // 存入收件人NFT集合
        depositRef.deposit(token: <-nft)
    }
}